filename = 'alice.txt'
# with open(filename, encoding='utf-8') as f:
#     contents = f.read()
# FileNotFoundError: [Errno 2] No such file or directory: 'alice.txt' 未找到文件异常，通常在读文件时发生

try:
    with open(filename, encoding='utf-8') as f:
        contents = f.read()
except FileNotFoundError:
    print(f"Sorry, the file {filename} does not exist.")
else:
    # 计算文件大概包含多少个单词
    words = contents.split() # split()方法把字符串以空格为分隔符拆分成一个由单词组成的列表
    num_words = len(words)
    print(f"The file {filename} has about {num_words} words.")